import os
import shutil

from src.const.code import Code
from src.util.rs import Rs


def remove_pycache_and_pyc(folder_path: str = ''):
    """
    删除 __pycache__ 文件夹和 .pyc 文件
    """
    for root, dirs, files in os.walk(folder_path):
        for d in dirs:
            if d == '__pycache__':
                shutil.rmtree(os.path.join(root, d))
        for f in files:
            if f.endswith('.pyc'):
                os.remove(os.path.join(root, f))


def clear_cache():
    """
    删除 __pycache__ 文件夹和 .pyc 文件
    """
    remove_pycache_and_pyc(os.path.join(os.path.dirname(__file__), "src"))
    return Rs(Code.OK, Code.message(Code.OK))


if __name__ == '__main__':
    print(clear_cache())
